package com.jinzecloud.blog.utils;

import java.util.HashMap;
import java.util.Map;

public class Result<T> extends HashMap<String,Object> {
    private T data;
    public T getData(){
        return data;
    };
    public void setData(T data){
        this.data = data;
    }

    public Result(){
        put("code",200);
        put("msg","success");
    }

    public static Result error(){
        return error(HttpStatus.SC_INTERNAL_SERVER_ERROR,"未知异常");
    }

    public static Result error(String msg){
        return error(HttpStatus.SC_INTERNAL_SERVER_ERROR,msg);
    }
    public static Result error(int code, String msg) {
        Result result = new Result();
        result.put("code",code);
        result.put("msg",msg);
        return result;
    }
    public static Result ok(String msg) {
        Result r = new Result();
        r.put("msg", msg);
        return r;
    }

    public static Result ok(Map<String, Object> map) {
        Result r = new Result();
        r.putAll(map);
        return r;
    }

    public static Result ok() {
        return new Result();
    }

    public Result put(String key, Object value) {
        super.put(key, value);
        return this;
    }

    public Integer getCode() {
        return (Integer) this.get("code");
    }

}
